<?php

#从Get中取参数
$name = $_GET["name"];
$deaths = $_GET["deaths"];

#连接数据库
$con = mysqli_connect("localhost","","");
if (!$con){
  die('Could not connect: ' . mysqli_error());
}
mysqli_select_db($con, "test");

#插入新记录
$sql = "insert into test(name, deaths) values('".$name."','".$deaths."')";
$result = mysqli_query($con, $sql);

#查询
$sql = "select * from test order by 'deaths' desc";
$result = mysqli_query($con, $sql);
if(!$result){
	die("sql query return null");
}
$ret = false;
while($row=mysqli_fetch_array($result)){
	$ret[] = array("name" => $row["name"], "deaths" => $row["deaths"]);
}

echo json_encode($ret);
?>
